<!--
 * @Author: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @Date: 2024-08-29 10:59:23
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-09-12 14:06:21
 * @FilePath: \ft-apply-admin\src\views\applicationDetails\RTComponent\InterviewTache\Entry\EntryComponent\EntryRegular.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="btns">
    <Button v-auth="'regularDimission'" color="#8B9FAB" @click="dimission">离职</Button>
    <BasicModal :show="dimissionShow" title="离职" width="30%" :widthComfirm="true" @comfirm="dimissionComfirm"
      @closeModal="dimissionShow = false">
      <template #content>
        <CommonForm :formList="dimissionFormList" ref="dimissionFormRef"></CommonForm>
      </template>
    </BasicModal>
  </div>
</template>

<script setup lang='ts'>
import { ref } from "vue";
import { Button } from "@/components/Button";
import BasicModal from "@/views/ApplicationDetails/Modals/BasicModal.vue";
import type { IndexFormItem } from "@/views/ApplicationDetails/application-type.ts";
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import { message } from "ant-design-vue";
import { confirmed } from "@/api/application-details/index.ts";
import { comStores } from '@/store/common/comStore';
const store = comStores()
const {userName} =store.userInFor
const dimissionShow = ref<boolean>(false);
const dimission = () => {
  // console.log('已转正', 'dimission')
  dimissionShow.value = true
}
const dimissionFormList = ref<IndexFormItem[]>([
  { label: "离职原因", name: "leavingReason", value: "", component: 'textarea', },
])
const dimissionFormRef = ref<any>(null)
const dimissionComfirm = async () => {
  const res = await dimissionFormRef.value.submitForm();
  if (!res) return;
  let param = {
    editStatus: "DEPART"
  }
  res.forEach(el => {
    param[el.name] = el.value
  })
  const data = await send(param);
  if (!data) return
  dimissionFormList.value.forEach(el => el.value = "")
  dimissionShow.value = false
}

const send = async (param) => {
  const { resumeId, processId } = store.currentResume;
  param.resumeId = resumeId
  param.processId = processId
  param.operator = userName
  const data = await confirmed(param);
  if (data && data.code === '10000') {
    store.getResumeInfo(resumeId)
    message.success("操作成功")
    return true
  } else {
    message.error(data.msg || "操作失败")
    return false
  }
}
</script>
<style lang="less" scoped>
.btns {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
</style>
